<template>
    <div>
        <title-a>选择所在地区</title-a>
            <ul>
                <li v-for="item in citys" :key="item.city_id" @click="togglecity({city_id:item.city_id,province_id:item.province_id,city_name:item.city_name})">{{item.city_name}}</li>
            </ul>
    </div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios'
// import '../../public/libs/js/axios.js'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      citys: []
    }
  },
  mounted () {
    this.isshow()

    // console.log(this.$route.params);
    // 设置axios为form-data
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
    axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded'
    axios.defaults.transformRequest = [function (data) {
      let ret = ''
      for (const it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }]
    // 然后再修改原型链
    Vue.prototype.$axios = axios

    console.log(this.$route.params)

    axios.post('/lct?api_version=2.3.0&platType=2&client=wap&isEncry=0&time=1583474376868&act=Address&op=get_region', {
      region: 'city_name',
      parent_id: this.$route.params.id
    }).then(res => {
      // console.log(111,res.data.datas)
      this.citys = res.data.datas
      console.log(this.citys)
    })
  },
  methods: {
    ...mapMutations(['isshow', 'ishide', 'city']),
    next (id) {
      console.log(id)
      this.$router.push('/address/city')
    },
    togglecity (citys) {
      this.city(citys)
      this.$router.push('/home')
    }
  },
  destroyed () {
    this.ishide()
  }
}
</script>
<style lang="scss" scoped>
    ul{
        width: 100%;
        margin-top: 50px;
        li{
            height: 30px;
            border-bottom: 1px solid #ccc;
            display: flex;
            // justify-content: center;
            align-items: center;
            padding: 10px;
            font-size: 15px;
        }
    }
</style>
